Slow Path (L1 + L2) 0 + 0
Full Loops (n) 0
Equation: L1 = (n * C) - L2
-
0
At meeting point: S = L1 + L2
Fast path: 2S = L1 + L2 + n*C
Subtracting equations: S = n*C
Result: L1 + L2 = n*C => L1 = (n*C) - L2
ListNode *detectCycle(ListNode *head) {    ListNode *slow = head, *fast = head;    while (fast && fast->next) {        slow = slow->next;        fast = fast->next->next;        if (slow == fast) {            ListNode *p1 = head, *p2 = slow;            while (p1 != p2) {                p1 = p1->next; p2 = p2->next;            }            return p1;        }    }    return nullptr;}
def detectCycle(head):    slow = fast = head    while fast and fast.next:        slow, fast = slow.next, fast.next.next        if slow == fast:            p1, p2 = head, slow            while p1 != p2:                p1, p2 = p1.next, p2.next            return p1    return None